﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pong.Core.Biz
{
    public class BizFactory
    {
        private static BizFactory instance = new BizFactory();
        public static BizFactory Instance
        {
            get { return instance; }
        }

        private IList<IBiz> all;

        public IList<IBiz> GetAll(Engine engine)
        {
            if (all != null) return all;

            return all = GetType().Assembly.GetTypes()
                .Where(t => typeof(IBiz).IsAssignableFrom(t) && t.IsClass && !t.IsAbstract)
                .Select(t => Activator.CreateInstance(t) as IBiz)
                .Select(b => { b.Engine = engine; return b; })
                .ToList();
        }
    }
}
